<?php
$logger = null;
abstract class Logger{
	protected function _info($str){}
	protected function _debug($str){}
	protected function _error($str){}
	protected function _fail($str){}
	
	static function info($str){
		global $logger;
		$logger->_info($str);
	}
	static function debug($str){
		global $logger;
		$logger->_debug($str);
	}
	static function error($str){
		global $logger;
		$logger->_error($str);
	}
	static function fail($str){
		global $logger;
		$logger->_fail($str);
	}
	static function createLogger($logLevel){
		global $logger;
		if ($logLevel == "info"){
			$logger = new LoggerInfo();
		}
		else if ($logLevel == "debug"){
			$logger = new LoggerDebug();
		}
		else if ($logLevel == "error"){
			$logger = new LoggerError();
		}
		else if ($logLevel == "fail"){
			$logger = new LoggerFail();
		}
		else{
			$logger = new LoggerNull();
		}
		return $logger;
	}
	protected function _println($logLevel, $str){
		$logLevelStr = str_pad("[$logLevel]", 5, " ", STR_PAD_RIGHT);
		$dtm = date("Y-m-d	H:i:s");
		$ln = "<br />\n";
		$logStr = "$logLevelStr [$dtm] [$str] $ln";
		//echo($logStr);
		error_log($logStr);
	}
}
class LoggerFail extends Logger{
	protected function _fail($str){
		$this->_println("fail", $str);
	}
}
class LoggerError extends LoggerFail{
	protected function _error($str){
		$this->_println("error", $str);
	}
}
class LoggerInfo extends LoggerError{
	protected function _info($str){
		$this->_println("info", $str);
	}
}
class LoggerDebug extends LoggerInfo{
	protected function _debug($str){
		$this->_println("debug", $str);
	}
}

class LoggerNull extends Logger{
}

Logger::createLogger(isset($logLevel) ? $logLevel : "debug");
?>